﻿//创建时间: 2010-12-15
//创建作者: 李 城
//功能说明: cms外部页面访问基类 动态访问 内容页
//最后修改: 2010-12-15
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using TRPOP.CMS.Business;
using TRPOP.CMS.Model;
using System.Web;

using TRPOP.Config;
using TRPOP.Common;

namespace TRPOP.CMS.Web.ExtraBus
{
    /// <summary>
    /// 动态访问 内容页
    /// </summary>
    public class Page_Load_content : BasePage
    {
        protected override void OnPreInit(EventArgs e)
        {
            if (!IsPostBack && ExecutePageURLCahche())
            {
                return;
            }
            base.OnPreInit(e);
        }

        protected override void OnInit(EventArgs e)
        {
            string strContentAutoPage = SYSConfig.SystemVar_ContentAutoPage.Remove(SYSConfig.SystemVar_ContentAutoPage.IndexOf("?"));
            string strDynamicPageName = 
                (base.mCurrentUrl.ToLower().Contains(strContentAutoPage.ToLower().Trim())) ? "Page_Load_content" : "";
            if (strDynamicPageName == "Page_Load_content")
                Load_content();
            else
                Base_Config.NotFound(base.Page, "CMS后台配置的页面地址和访问的页面不一致(内容页)");
            //base.OnInit(e);
        }

        /// <summary>
        /// 动态访问 内容页
        /// </summary>
        public void Load_content()
        {
            int m_intId = 0;
            int m_intPageindex = 0;
            m_intId = RequestHelper.RequestInt("id");
            m_intPageindex = RequestHelper.RequestInt("page");
            if (m_intId <= 0)
            {
                Base_Config.NotFound(base.Page, "访问的信息id<= 0");
            }
            object obj = TRPOP.CMS.Publish.PublishAccess.GetOneContentPage(m_intId);
            if (obj is string || obj is ArrayList)
            {
                if (m_intPageindex <= 0)
                    m_intPageindex = 1;
                Response.Clear();
                Response.ClearHeaders();
                Response.ClearContent();
                if (obj is string)
                    Response.Write(obj.ToString());
                else if ((m_intPageindex) <= (obj as ArrayList).Count)
                {
                    if (base.mBlnEnableCache)
                        base.mICache.Save(base.mCacheKey, (obj as ArrayList)[m_intPageindex - 1].ToString(), BasePage.mCacheSeconds);
                    Response.Write((obj as ArrayList)[m_intPageindex - 1].ToString());
                }
                else
                    Base_Config.NotFound(base.Page, "访问的信息不存在[模板未指定或信息不存在]");
                Response.End();
            }
            else
                Base_Config.NotFound(base.Page, "访问的信息不存在[模板未指定或信息不存在]");
        }

       
    }
}
